package com.tools.util;


public class RegexUtil {

    public RegexUtil() {
    }

    private static boolean isMatches(String str, String regexStr, boolean isTrim) {
        if (str == null || regexStr == null)
            return false;
        if (isTrim)
            str = str.trim();
        return str.matches(regexStr);
    }

    public static boolean isInt(String str, boolean isTrim) {
        return isMatches(str, "^-?\\d+$", isTrim);
    }

    public static boolean isIntPlus(String str, boolean isTrim) {
        return isMatches(str, "^\\d+$", isTrim);
    }

    public static boolean isIntDec(String str, boolean isTrim) {
        return isMatches(str, "^-\\d+$", isTrim);
    }

    public static boolean isLong(String str, boolean isTrim) {
        return isMatches(str, "^-?\\d+$", isTrim);
    }

    public static boolean isLongPlus(String str, boolean isTrim) {
        return isMatches(str, "^\\d+$", isTrim);
    }

    public static boolean isLongDec(String str, boolean isTrim) {
        return isMatches(str, "^-\\d+$", isTrim);
    }

    public static boolean isDouble(String str, boolean isTrim, boolean acceptE) {
        if (acceptE) {
            return isMatches(str, "^-?\\d+(\\.\\d+((e|E)\\d+)?)?$", isTrim);
        } else {
            return isMatches(str, "^-?\\d+(\\.\\d+)?$", isTrim);
        }
    }

    public static boolean isDoublePlus(String str, boolean isTrim, boolean acceptE) {
        if (acceptE) {
            return isMatches(str, "^\\d+(\\.\\d+((e|E)\\d+)?)?$", isTrim);
        } else {
            return isMatches(str, "^\\d+(\\.\\d+)?$", isTrim);
        }
    }

    public static boolean isDoubleDec(String str, boolean isTrim, boolean acceptE) {
        if (acceptE) {
            return isMatches(str, "^-\\d+(\\.\\d+((e|E)\\d+)?)?$", isTrim);
        } else {
            return isMatches(str, "^-\\d+(\\.\\d+)?$", isTrim);
        }
    }
}
